package chatclient.applets.components;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;

public class Border {

    public Border(Image image, Image image1, Image image2, Image image3, Image image4, Image image5, Image image6,
            Image image7) {
        sync = new Object();
        topLeft = image;
        left = image1;
        bottomLeft = image2;
        top = image3;
        bottom = image4;
        topRight = image5;
        right = image6;
        bottomRight = image7;
    }

    public int getTopHeight() {
        return top != null ? top.getHeight(null) : 0;
    }

    public int getBottomHeight() {
        return bottom != null ? bottom.getHeight(null) : 0;
    }

    public int getTotalHeight() {
        return getTopHeight() + getBottomHeight();
    }

    public int getLeftWidth() {
        return left != null ? left.getWidth(null) : 0;
    }

    public int getRightWidth() {
        return right != null ? right.getWidth(null) : 0;
    }

    public int getTotalWidth() {
        return getLeftWidth() + getRightWidth();
    }

    public void paint(ImageObserver imageobserver, Graphics g, int i, int j, int k, int l) {
        synchronized (sync) {
            int i1 = i;
            int j1 = j;
            if (topLeft != null) {
                g.drawImage(topLeft, i1, j1, imageobserver);
            }
            j1 += Math.max(0, getTopHeight());
            if (left != null) {
                for (int k1 = 0; k1 < l; k1 += Math.max(1, left.getHeight(imageobserver))) {
                    g.drawImage(left, i1, j1 + k1, imageobserver);
                }

            }
            j1 += l;
            if (bottomLeft != null) {
                g.drawImage(bottomLeft, i1, j1, imageobserver);
            }
            j1 += Math.max(0, getBottomHeight());
            i1 += Math.max(0, getLeftWidth());
            j1 = j;
            if (top != null) {
                for (int l1 = 0; l1 < k; l1 += Math.max(1, top.getWidth(imageobserver))) {
                    g.drawImage(top, i1 + l1, j1, imageobserver);
                }

            }
            j1 += Math.max(0, getTopHeight());
            j1 += l;
            if (bottom != null) {
                for (int i2 = 0; i2 < k; i2 += Math.max(1, bottom.getWidth(imageobserver))) {
                    g.drawImage(bottom, i1 + i2, j1, imageobserver);
                }

            }
            j1 += Math.max(0, getBottomHeight());
            i1 += k;
            j1 = j;
            if (topRight != null) {
                g.drawImage(topRight, i1, j1, imageobserver);
            }
            j1 += Math.max(0, getTopHeight());
            if (right != null) {
                for (int j2 = 0; j2 < l; j2 += Math.max(1, right.getHeight(imageobserver))) {
                    g.drawImage(right, i1, j1 + j2, imageobserver);
                }

            }
            j1 += l;
            if (bottomRight != null) {
                g.drawImage(bottomRight, i1, j1, imageobserver);
            }
            j1 += Math.max(0, getBottomHeight());
            i1 += Math.max(0, getRightWidth());
        }
    }
    private final Object sync;
    private Image topLeft;
    private Image left;
    private Image bottomLeft;
    private Image top;
    private Image bottom;
    private Image topRight;
    private Image right;
    private Image bottomRight;
}
